//引入vue和vuex
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const store = new Vuex.Store({ //全局变量定义
	state: {
		baseUrl: 'https://www.sdvoda.com/beedao',
		// baseUrl: 'http://192.168.0.106:8082',
		// baseUrl: 'http://192.168.0.193:8082', // 高学治
		// baseUrl: 'http://192.168.0.194:8082', // 宋世宇
		// baseUrl: 'http://121.89.180.178:8082', //线上
		// baseUrl: 'http://121.36.52.112:8082', //线上远程
		// baseUrl: 'https://www.beedao.tech/api', //线上
		// baseUrl: 'https://www.dangkangtech.com/api', //线上
		forcedLogin: false, //是否需要强制登录
		hasLogin: false,
		uerInfo: {
			userName: "",
			userId: '',
			token: '',
		}
	},
	mutations: {
		login(state, user) {
			state.hasLogin = true;
			state.uerInfo.userName = user.account || '';
			state.uerInfo.userId = user.userId || '';
			state.uerInfo.token = user.token || '';
			uni.setStorage({ //将用户信息保存在本地  
				key: 'uerInfo',
				data: user
			})
		},
		logout(state) {
			state.hasLogin = false;
			state.uerInfo = {}
			uni.removeStorage({
				key: 'uerInfo'
			})
			uni.removeStorage({
				key: 'orderMeal'
			})
			setTimeout(function(){
				uni.navigateTo({
					url: '/pages/register/login'
				});
			},1000)
		}
	}
})
export default store
